package com.itHsuSE.homework;

import java.util.Scanner;

public class HomeWork1_2 {
    public static void main(String[] args) {
        //定义flag标志是否有马鞍数
        boolean flag = true;
        System.out.println();
        /*
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入是一个n行n列的矩阵n的大小：");
        int n = sc.nextInt();
        int[][] map = new int[n][n];
        System.out.println("请输入矩阵的值");
        */

        //Scanner sc = new Scanner(System.in);

        int[][] map={
                {9,8,7,6,5,4,3,2},
                {8,8,9,9,9,9,9,9},
                {3,7,7,6,5,4,2,1},
                {8,8,3,2,1,7,3,2},
                {7,5,3,2,9,1,3,2},
                {6,3,2,1,9,3,1,3},
                {8,2,1,3,5,8,9,1},
                {1,3,2,1,3,5,6,8},
                {9,3,1,2,3,4,5,8}//测试用例
                /*{1,2,3},
                {4,5,6},
                {7,8,9}*/
        };

        /*for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[0].length; j++) {
                map[i][j] = sc.nextInt();
            }
        }*/

        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[i].length; j++) {
                //通过两个方法确定这个数是否是马鞍数，如果是则打印对应的 行 列 值，并且将flag置为false
                if (isRowMin(map, i, j) && isColMax(map, i, j)) {
                    System.out.println((i + 1) + " " + (j + 1) + " " + map[i][j]);
                    flag = false;
                }
            }
        }
        if (flag) {
            System.out.println("没有马鞍数");
        }
    }

    public static boolean isRowMin(int[][] map, int i, int j) {
        for (int k = 0; k < map[i].length; k++) {//i表示行
            if (map[i][k] < map[i][j]) {//如果有比它小的，证明这个点不是该行最小值
                return false;
            }
        }
        return true;
    }

    public static boolean isColMax(int[][] map, int i, int j) {
        for (int k = 0; k < map[j].length; k++) {//j表示列
            if (map[k][j] > map[i][j]) {//如果有比它大的，证明这个点不是该列最大值
                return false;
            }
        }
        return true;
    }
}
